import static java.lang.Thread.sleep;

/**
 * Creat with IntelliJ IDEA
 * Description
 * User: mamba24
 * Date: 2022-08-10
 * Time: 20:57
 * To BE A Better Person-2020-3-2
 */
public class TestDemo3 {
    public static Object locker=new Object();
    public static void main(String[] args) throws InterruptedException {
        Thread t1=new Thread(()->{
            synchronized (locker){

                    try {
                        locker.wait();
                        for (int i = 0; i < 2; i++) {
                            System.out.println("我是线程1");
                        }
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }

            }
        });
        Thread t2=new Thread(()->{
            synchronized (locker){
                for (int i = 0; i < 2; i++) {

                    System.out.println("我是线程2");

                }
                try {
                    sleep(2000);
                    locker.notify();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

            }
        });
        t1.start();
        t2.start();
        sleep(20);
        System.out.println("t1 state>"+t1.getState());
        System.out.println("t2 state>"+t2.getState());
    }
}
